package com.xkdx.guangguang.fragment.home.homedetail;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.xkdx.guangguang.module.network.AbsModule;
import com.xkdx.guangguang.shareclass.HomeListInfoDetail;

public class HomeDetailModule extends AbsModule {
	public HomeDetailAllInfo homedetailAllInfo;
	@Override
	public void parseData() throws Exception {
		backJson = (JSONArray) result;
		try {
			for (int i = 0; i < backJson.length(); i++) {
				jsonObj = (JSONObject) backJson.get(i);
				String sortOfAct = jsonObj.getString("Act");
				if (sortOfAct.equals("getInfoDetail")) {
					homedetailAllInfo = parserHomedetailAllInfo(jsonObj.getJSONObject("Content"));
				}

			}
		} catch (Exception e) {
			throw e;
		}

	}
	
	
	// 处理首页详情资讯信息
		private HomeDetailAllInfo parserHomedetailAllInfo(JSONObject person) throws Exception{
			HomeDetailAllInfo homedetailAllInfo=new HomeDetailAllInfo();
			HomeDetail homeDetail=new HomeDetail();
			ArrayList<HomeListInfoDetail> homeListInfoDetail=new ArrayList<HomeListInfoDetail>();;
			try {
				if (person == null) {
					return homedetailAllInfo;
				}
				JSONObject stut = (JSONObject) person.get("Result");
				homedetailAllInfo.setStatus(stut.getString("Status"));
				JSONObject item = (JSONObject) stut.get("DetailInfo");
				homeDetail.setInfoID(item.getString("InfoID"));
				homeDetail.setBegintime(item.getString("BeginTime"));
				homeDetail.setCollectCount(item.getString("CollectCount"));
				homeDetail.setCommentCount(item.getString("CommentCount"));
				homeDetail.setEndTime(item.getString("EndTime"));
				homeDetail.setInfoContent(item.getString("InfoContent"));

				// JSONArray pics = (JSONArray) item.get("PictureUrl");
				// for (int j = 0; j < pics.length(); j++) {
				// homeDetail.getPictureList().add(pics.getString(j));
				List<String> piclist = new ArrayList<String>();
				JSONArray array = item.getJSONArray("PictureUrl");
				for (int i = 0; i < array.length(); i++) {
					String l = (String) array.getString(i);
					piclist.add(l);
					homeDetail.setPictureList(piclist);
				}

				JSONArray listinfo = (JSONArray) stut.getJSONArray("ListInfo");
				for (int k = 0; k < listinfo.length(); k++) {

					JSONObject jDetail = (JSONObject) listinfo.opt(k);
					HomeListInfoDetail list = new HomeListInfoDetail();
					list.setShopID(jDetail.getString("ShopID"));
					list.setShopName(jDetail.getString("ShopName"));
					list.setBrandID(jDetail.getString("BrandID"));
					list.setBrandName(jDetail.getString("BrandName"));
					list.setAddress(jDetail.getString("Address"));
					list.setPhone(jDetail.getString("Phone"));
					list.setWebSiteUrl(jDetail.getString("WebSiteUrl"));
					list.setShopType(jDetail.getString("ShopType"));
					homeListInfoDetail.add(list);
				}

				homedetailAllInfo.setHomeDtail(homeDetail);
				homedetailAllInfo.setHomeListInfoDetail(homeListInfoDetail);

			} catch (Exception e) {
				throw e;
			}

			return homedetailAllInfo;
		}
		public class HomeDetailAllInfo {
			
			private String Type;
			private String Status; // Success或者 Error
			private String ErrorCodel;
			private String Message;
			private HomeDetail homeDtail;
			private ArrayList<HomeListInfoDetail> homeListInfoDetail;

			
			public String getType() {
				return Type;
			}

			public void setType(String type) {
				Type = type;
			}

			public String getStatus() {
				return Status;
			}

			public void setStatus(String status) {
				Status = status;
			}

			public String getErrorCodel() {
				return ErrorCodel;
			}

			public void setErrorCodel(String errorCodel) {
				ErrorCodel = errorCodel;
			}

			public String getMessage() {
				return Message;
			}

			public void setMessage(String message) {
				Message = message;
			}

			public void setHomeDtail(HomeDetail homeDtail) {
				this.homeDtail = homeDtail;
			}

			public HomeDetail getHomeDtail() {
				return homeDtail;
			}

			public void setHomeListInfoDetail(ArrayList<HomeListInfoDetail> homeListInfoDetail) {
				this.homeListInfoDetail = homeListInfoDetail;
			}

			public ArrayList<HomeListInfoDetail> getHomeListInfoDetail() {
				return homeListInfoDetail;
			}


		}
		
		public class HomeDetail {
			String InfoID;
			String InfoTitle;
			String InfoContent;
			List<String> pictureList;
			String Begintime;
			String EndTime;
			String CollectCount;
			String CommentCount;

			public HomeDetail() {
				super();
				pictureList = new ArrayList<String>();

			}

			public String getInfoID() {
				return InfoID;
			}

			public void setInfoID(String infoID) {
				InfoID = infoID;
			}

			public String getInfoTitle() {
				return InfoTitle;
			}

			public void setInfoTitle(String infoTitle) {
				InfoTitle = infoTitle;
			}

			public String getInfoContent() {
				return InfoContent;
			}

			public void setInfoContent(String infoContent) {
				InfoContent = infoContent;
			}

			public List<String> getPictureList() {
				return pictureList;
			}

			public void setPictureList(List<String> pictureList) {
				this.pictureList = pictureList;
			}

			public String getBegintime() {
				return Begintime;
			}

			public void setBegintime(String begintime) {
				Begintime = begintime;
			}

			public String getEndTime() {
				return EndTime;
			}

			public void setEndTime(String endTime) {
				EndTime = endTime;
			}

			public String getCollectCount() {
				return CollectCount;
			}

			public void setCollectCount(String collectCount) {
				CollectCount = collectCount;
			}

			public String getCommentCount() {
				return CommentCount;
			}

			public void setCommentCount(String commentCount) {
				CommentCount = commentCount;
			}

		}
		
		

}
